/*************************************************************************
  > File Name: BuiltinPrefetch.cpp
  > Author: 16hxliang3
  > Mail: 16hxliang3@stu.edu.cn
  > Created Time: Wed 23 Mar 2022 03:46:15 PM CST
 ************************************************************************/

#include <cstdlib>
#include <ctime>
#include <iostream>
int main()
{
    int n = 1000000;
    int i, j = 1;
    int a[n], b[n];
    double start, eend;
    start = clock(); //程序开始计时
    for (i = 0; i < n; i++)
    {
        a[i] = i;
        b[i] = n - i;
        /* __builtin_prefetch(&a[i + j], 1);
         * __builtin_prefetch(&b[i + j], 1); */
        /* ... */
    };
    for (i = 0; i < n; i++)
    {
        a[i] = (a[i] * b[i])^2;
        /* __builtin_prefetch(&a[i + j], 1);
         * __builtin_prefetch(&b[i + j], 0); */
        /* ... */
    };
    eend = clock(); //程序结束用时
    double endtime = (double)(eend - start) / CLOCKS_PER_SEC;
    std::cout << "Total time:" << endtime << std::endl; // s为单位
}
